use crate::http::client;
use crate::http::client::rpc;
use std::sync::Arc;

pub use rpc::Auth;
pub use rpc::Setting;

pub struct Client {
    pub auth: Arc<client::auth::AuthClient>,
    pub node: Arc<client::node::NodeClient>,
    pub endpoint: Arc<client::endpoint::EndpointClient>,
    pub endpoint_peer: Arc<client::endpoint_peer::EndpointPeerClient>,
    pub endpoint_wireguard_config:
        Arc<client::endpoint_wireguard_config::EndpointWireguardConfigClient>,
    pub endpoint_peer_wireguard_config:
        Arc<client::endpoint_peer_wireguard_config::EndpointPeerWireguardConfigClient>,
}

impl Client {
    pub fn new(setting: Setting, auth: Arc<Auth>) -> Self {
        let rpc_client = Arc::new(rpc::Client::new(setting, reqwest::Client::new(), auth));
        Self {
            auth: Arc::new(client::auth::AuthClient::new(rpc_client.clone())),
            node: Arc::new(client::node::NodeClient::new(
                rpc_client.clone(),
            )),
            endpoint: Arc::new(client::endpoint::EndpointClient::new(rpc_client.clone())),
            endpoint_peer: Arc::new(client::endpoint_peer::EndpointPeerClient::new(
                rpc_client.clone(),
            )),
            endpoint_wireguard_config: Arc::new(
                client::endpoint_wireguard_config::EndpointWireguardConfigClient::new(
                    rpc_client.clone(),
                ),
            ),
            endpoint_peer_wireguard_config: Arc::new(
                client::endpoint_peer_wireguard_config::EndpointPeerWireguardConfigClient::new(
                    rpc_client,
                ),
            ),
        }
    }
}
